<!DOCTYPE html>
<html lang="en">
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">

    <link href="/static/easyui/themes/insdep/easyui.css" rel="stylesheet" type="text/css">
    <link href="/static/easyui/themes/insdep/easyui_animation.css" rel="stylesheet" type="text/css">
    <link href="/static/easyui/themes/insdep/easyui_plus.css" rel="stylesheet" type="text/css">
    <link href="/static/easyui/themes/insdep/insdep_theme_default.css" rel="stylesheet" type="text/css">
    <link href="/static/easyui/themes/insdep/icon.css" rel="stylesheet" type="text/css">
    <link href="/static/easyui/themes/color.css" rel="stylesheet" type="text/css">

    <link href="/static/ztree/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css">
    <link href="/static/css/common.css" rel="stylesheet" type="text/css">

    <script type="text/javascript" src="/static/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/static/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/easyui/themes/insdep/jquery.insdep-extend.min.js"></script>
    <script type="text/javascript" src="/static/ztree/jquery.ztree.all.min.js"></script>
    <script type="text/javascript" src="/static/easyui/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/static/kindeditor/kindeditor-all-min.js"></script>

</head>

<body>
<div>
    <span>客户视图：</span><span onclick="return whole('manage/customer/CustomerAction_pagination.action')"
                            class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true">全部</span>|
    <span onclick="return myCustomer('manage/customer/CustomerAction_myCustomer.action')" class="easyui-linkbutton"
          data-options="plain:true">我的客户</span>|
    <span onclick="return subCustomer('manage/customer/CustomerAction_subCustomer.action')" class="easyui-linkbutton"
          data-options="plain:true">下属客户</span>
    &nbsp;&nbsp;&nbsp;
    <span onclick="return todayCreate('manage/customer/CustomerAction_todayCreate.action')" class="easyui-linkbutton"
          data-options="iconCls:'icon-ok',plain:true">今日新建</span>|
    <span onclick="return weekCreate('manage/customer/CustomerAction_weekCreate.action')" class="easyui-linkbutton"
          data-options="plain:true">本周新建</span>|
    <span onclick="return monthCreate('manage/customer/CustomerAction_monthCreate.action')" class="easyui-linkbutton"
          data-options="plain:true">本月新建</span>|
    <span onclick="return followed('manage/customer/CustomerAction_followed.action')" class="easyui-linkbutton"
          data-options="plain:true">我关注的</span>|
    <span onclick="shared" class="easyui-linkbutton" data-options="plain:true">我共享的</span>|
    <span id="sharedTome" class="easyui-linkbutton" data-options="plain:true">共享给我的</span>
    &nbsp;&nbsp;&nbsp;
    <span id="recycleBin" class="easyui-linkbutton" data-options="iconCls:'icon-recover_deleted',plain:true">回收站</span>
    &nbsp;
    <span id="advancedSearch" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">高级搜索</span>
</div>

<div id="tool" style="margin-bottom: 20px">
    <table>
        <tr>
            <td>
                <i class="iconfont"></i>
                <select name="batchOperate" style="width:100px;height:25px;">
                    <option value="-1">批量操作</option>
                    <option value="0">批量放入线索池</option>
                    <option value="1">批量关注</option>
                    <option value="2">批量共享</option>
                    <option value="3">取消关注</option>
                    <option value="4">取消共享</option>
                    <option value="5">批量删除</option>
                </select>
            </td>
            <form action="likeCustomer" method="post">
                <td>
                    <select name="filterSearch" style="width:100px;height:25px;">
                        <option value="-1">&#45;&#45;请选择筛选条件&#45;&#45;</option>
                        <option value="lname">按公司名查询</option>
                        <option value="addr">按地址查询</option>
                    </select>
                    <select name="contain" style="width:60px;height:25px;">
                        <option value="-1">&#45;&#45;包含&#45;&#45;</option>
                    </select>
                </td>
                <td class="text-content">
                    <input name="search" type="text" placeholder="请输入查询关键字">
                    <input class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" type="submit" value="搜索">
<!--                    <span id="search" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">搜索</span>-->
                </td>
                <td>
            </form>
            <span id="chat" class="easyui-linkbutton" data-options="iconCls:'icon-cut',plain:true">发送短信</span>
            <span id="email" class="easyui-linkbutton" data-options="iconCls:'icon-redo',plain:true">发送邮件</span>
            </td>
            <td>
                <span onclick="return add('toAdd')" class="easyui-linkbutton"
                      data-options="iconCls:'icon-add',plain:true">新建线索</span>
                <span id="tool" class="easyui-linkbutton" data-options="iconCls:'icon-cog',plain:true">客户工具</span>
            </td>
        </tr>
    </table>
</div>
<div id="leadsLs"></div>
</body>

<script type="text/javascript">
    $(function () {
        //分页展示客户列表
        $("#leadsLs").datagrid({
            url: "/listLead",
            checkOnSelect: false,
            idField: "leadsId",
            pagination: true,
            sortName: "leadsId",
            columns: [
                [
                    {field: "选择", checkbox: true},
                    {field:"id", hidden: true},
                    {field:"name",title:"公司名"},
                    {field:"contactsName",title:"联系人姓名"},
                    {field:"saltname",title:"尊称"},
                    {field:"mobile",title:"手机"},
                    {field:"nextstep",title:"下联系内容"},
                    {field:"nextstepTime",title:"下次联系时间"},
                    {field:"ownerName",title:"负责人"},
                    {field:"createName",title:"创建人"},
                    {field:"createTime",title:"创建时间"},
                    {field:"dffday",title:"据到期天数"},
                    {
                        field: "operation", title: "操作", width: 100, formatter: function (value, rowData, index) {
                            return "<a href='javascript:void(0);' onclick=\"return see(\'toSee\',\'" + rowData.id + "\')\">查看</a>" +
                                " <a href='javascript:void(0);' onclick=\"return modify(\'toEditLead\',\'" + rowData.id + "\')\">编辑</a>" +
                                " <a href='javascript:void(0);' onclick=\"return remove(\'toDeleteLeads\',\'" + rowData.id + "\')\">删除</a>"
                        }
                    }
                    ]
                ],
            loadFilter: function (data) {
                return {total: data.total, rows: data.rows}
            }

        })
    })

    //查询全部客户
    function whole(url) {
        $("#customerLs").datagrid({
            "url": url
        })
    }

    //查询我的客户
    function myCustomer(url) {
        $("#customerLs").datagrid({
            "url": url
        })
    }

    //查询当前员工下属创建的客户
    function subCustomer(url) {
        $("#customerLs").datagrid({
            "url": url
        })
    }

    //查询今天创建的客户
    function todayCreate(url) {
        $("#customerLs").datagrid({
            "url": url + "?type=day"
        })
    }

    //查询周创建的客户
    function weekCreate(url) {
        $("#customerLs").datagrid({
            "url": url + "?type=week"
        })
    }

    //查询月创建的客户
    function monthCreate(url) {
        $("#customerLs").datagrid({
            "url": url
        })
    }

    //查询当前用户关注的客户
    function followed(url) {
        $("#customerLs").datagrid({
            "url": url
        })
    }

    //页面添加线索
    function add(url) {
        parent.parent.openTopWindow({
            "url": url,
            "width": 800,
            "height": 700,
            "title": "新建线索",
            close: function () {
                $("#customerLs").datagrid("reload");
            }
        })
    }

    //修改客户
    function modify(url, id) {
        parent.parent.openTopWindow({
            "url":url+"?id="+id,
            "width":800,
            "height":700,
            "title":"新建客户",
            close:function(){
                $("#leadsLs").datagrid("reload");
            }
        })
    }

    //查看客户
    function see(url, id) {
        parent.parent.openTopWindow({
            "url":url+"?id="+id,
            "width":800,
            "height":700,
            "title":"客户信息",
            close:function(){
                $("#leadsLs").datagrid("reload");
            }
        })
    }
    //删除按钮事件处理函数
    function remove(url){
        //获取到选中的一行数据
        var rows = $("#leadsLs").datagrid("getChecked");
        if(!rows.length){
            $.messager.alert("警告","请选择要删除的数据");
            return;
        }
        $.messager.confirm("警告","数据删除后无法恢复，是否确认删除",function(b){
            if(b){
                var ids = new Array();
                $.each(rows,function(index,obj){
                    ids.push(obj.id);
                });
                //将数组中元素使用,分割拼接为一个字符串
                ids = ids.join(",");
                $.post(url,
                    {
                        "ids" : ids
                    },
                    function(data){
                        if(data && data.success){
                            $.messager.alert("提示",data.message);
                            $("#customerLs").datagrid("reload");
                            return;
                        }
                        $.messager.alert("警告",data.message);
                    },"json");
            }
        });
    }
</script>
<script type="text/javascript">
    $(function () {
        //邮件发送
        $("#email").on("click", function (e) {
            var rows = $("#customerLs").datagrid("getSelections");
            var rowCode = rows[0].zipCode;
            if (!rows || rows.length == 0) {
                $.messager.alert("警告", "请选中要发送邮件的客户");
                return;
            }else {
                location.href = "toEmail?rows=" + rowCode ;
            }
        })
    })
</script>
</html>